﻿<?php
require_once dirname(__FILE__) . '/includes/common.inc.php';
require_once dirname(__FILE__) . "/database/$database/database.inc.php";
  
header('Content-Type: text/plain');

$q = json_decode(MiscUtils::getParam('q', NULL));


try {
  $myManager->start_t();
  foreach ($q as &$tmp) {
    $orm = classToOrm($tmp->n);
    if ($orm) {
      foreach ($tmp->a as &$obj) {
        if (isset($obj->e_oid)) {
          $orm->update($myManager, $obj);
        } else {
          $orm->add($myManager, $obj);
        }
      }
      foreach ($tmp->r as &$obj) {
        $orm->remove($myManager, $obj);
      }
    }
  }
  $myManager->commit_t();
  echo json_encode(array());
} catch (PDOException $e) {
  echo MiscUtils::encode($e->getMessage());
}
?>